package com.luck.easyfoodbatch.mvp.mine;

import android.content.Context;
import android.support.annotation.Nullable;

import com.luck.easyfoodbatch.callback.JsonCallback;
import com.luck.easyfoodbatch.mvp.model.ApplyShop;
import com.luck.easyfoodbatch.util.HttpUtil;
import com.lzy.okhttputils.OkHttpUtils;
import com.lzy.okhttputils.cache.CacheMode;
import com.lzy.okhttputils.model.HttpParams;

import okhttp3.Call;
import okhttp3.Request;
import okhttp3.Response;

/**
 * author：luck
 * project：EasyFoodBatch
 * package：com.luck.easyfoodbatch.mvp.mine
 * email：893855882@qq.com
 * data：16/10/21
 */
public class ApplyShopPresenter implements ApplyShopModel {
    private final String TAG = getClass().getSimpleName();
    private ApplyShopView applyShopView;
    private Context mContext;

    public ApplyShopPresenter(ApplyShopView applyShopView, Context mContext) {
        this.applyShopView = applyShopView;
        this.mContext = mContext;
    }


    @Override
    public void applyShop(String seller_type, String name, String phone, String shop_avatar, String shop_name, String shop_address, String id_card, String product_type, String brand, String real_goods, String send_ontime, String three_days_on, String is_agree_commission) {
        HttpParams params = new HttpParams();
        params.put("seller_type", seller_type);
        params.put("name", name);
        params.put("phone", phone);
        params.put("shop_avatar", shop_avatar);
        params.put("shop_name", shop_name);
        params.put("shop_address", shop_address);
        params.put("id_card", id_card);
        params.put("product_type", product_type);
        params.put("brand", brand);
        params.put("real_goods", real_goods);
        params.put("send_ontime", send_ontime);
        params.put("three_days_on", three_days_on);
        params.put("is_agree_commission", is_agree_commission);
        OkHttpUtils.post(HttpUtil.APPLY_SHOPER)
                .tag(this)
                .cacheMode(CacheMode.DEFAULT)
                .cacheKey(TAG)
                .params(params)
                .execute(new JsonCallback(mContext, ApplyShop.class) {

                    @Override
                    public void onResponse(boolean isFromCache, Object data, Request request, @Nullable Response response) {
                        applyShopView.applyShopSuccess((ApplyShop) data);
                        applyShopView.hideLoading();
                    }

                    @Override
                    public void onError(boolean isFromCache, Call call, @Nullable Response response, @Nullable Exception e) {
                        super.onError(isFromCache, call, response, e);
                        applyShopView.hideLoading();
                        applyShopView.httpStatusError();
                    }
                });
    }
}
